package com.ghc.androidexample.share;

import com.ghc.androidexample.R;
import com.ghc.androidexample.R.id;
import com.ghc.androidexample.R.layout;
import com.ghc.androidexample.R.menu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class ShareActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_share);
		// Get intent
		Intent intent = getIntent();
		String action = intent.getAction();
		String type = intent.getType();
		if (action != null && action.equals(Intent.ACTION_SEND) && type != null) {
			if (type.equalsIgnoreCase("text/plain")) {
				processSendText(intent);
			}
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.share, menu);
		return true;
	}

	private void processSendText(Intent intent) {
		String text = intent.getStringExtra(Intent.EXTRA_TEXT);
		if (text != null) {
			TextView tv = (TextView) findViewById(R.id.txtShare_Text);
			tv.setText(text);
		}
	}
}
